# -*- coding: utf-8 -*-
from imp import reload
import codecs
import jieba
import xlrd
import os
import  xlwt
from GaoDing.Deal_dictionary import read_excel
from GaoDing.Deal_doc import read_lines, segmentation

if __name__ == '__main__':
    newsFoldersPath = "news"  # 文档地址
    pathDir = os.listdir(newsFoldersPath)
    children=[]
    #字典处理
    sent_word_list = read_excel('emotion.xlsx')
    info=[]
    for allDir in pathDir:
        children.append(os.path.join('%s/%s' % (newsFoldersPath, allDir)))
    for child in children:
        #对每个文本处理
        count=0

        line=read_lines(child)
        str=''
        for s in line:
            str += s
        news_list = segmentation(str)
        for wordInDic in sent_word_list:
            for a in news_list:
                if(wordInDic==a):
                    count+=1
        info.append(count)

    #生成Excel文件
    file = xlwt.Workbook()
    t = file.add_sheet('资料库')
    t.write(0, 0, '文档次序（按news文件夹中排列）')
    t.write(0, 1, '统计')
    print(len(children))
    for i in range(0,len(children)):
        t.write(i+2,0,i)
        t.write(i + 2, 1, info[i])
        
    #生成统计xls文件
    file.save('写你自己的路径/GaoDing.xls')















